// var modernBrowser = (
//   'fetch' in window &&
//   'assign' in Object
// );
//
// if (!modernBrowser) {
//   var scriptElement = document.createElement('script');
//
//   scriptElement.async = false;
//   scriptElement.src = '/polyfills.bundle.js';
//   document.head.appendChild(scriptElement);
// }

// import 'babel-polyfill';

// import  './polyfills';
import uinv from './uinv';
// import _ from 'lodash';
import './style.css';

import cold from './images/cold1-10.svg';
import data from './data/data.xml';
import printMe from './print.js';
import {cube} from './math.js';
import {isProduct, baseUrl} from "./config";
// import { file, parse } from  "./globals";

window.isProduct = isProduct;
window.baseUrl = baseUrl;
global.uinv = uinv;
let s = Symbol();
// let s = "a";

async function a() {
  try{
    await Promise.reject('出错了！')
  }catch (e){
    return await Promise.resolve('请重新填写')
  }
}
a().then(function (err) {
  console.log(err);
}).catch(function (err) {
  console.log(err);
})

if ('serviceWorker' in navigator) {
  window.addEventListener('load', () => {
    navigator.serviceWorker.register('/service-worker.js').then(registration => {
      console.log('SW registered: ', registration);
    }).catch(registrationError => {
      console.log('SW registration failed: ', registrationError);
    });
  });
}

function component() {
  console.log(s);

  var element = document.createElement('div');
  var btn = document.createElement('button');

  var _cube = cube(5);
  element.innerHTML = join(//_.join
    ['Hello', 'webpack',
      uinv.isFunction('aa'), '中国',
      '5 cubed is equal to ' + _cube
    ], ' ');

  element.classList.add('hello');

  // var myIcon = new Image();
  // myIcon.src = cold;
  // element.appendChild(myIcon);
  // console.log(data);

  btn.innerHTML = 'Click me and check the console!';
  btn.onclick = printMe;
  // btn.onclick = function (e) {
  //   import('./print').then(function (module) {
  //     var print = module.default;
  //     print();
  //   })
  // };
  element.appendChild(btn);

  // this.alert('Hmmm, this probably isn\'t a great idea...')

  return element;
}

// if(module.hot){
//   module.hot.accept('./print.js',function () {
//     console.log('Accepting the updated printMe module!');
//     printMe();
//   });
// }

document.body.appendChild(component());
